import tkinter as tk
from tkinter import messagebox
from db import db
from AdminPage import AdminPage
from StaffPage import StaffPage
class MainPage:
    def __init__(self, frame, root):
        self.frame = frame
        self.root = root

    def function_login(self, username, password):
        self.username = username
        self.password = password
        if self.username == "" or self.password == "":
            tk.messagebox.showinfo("提示信息", "注册信息不完整,请填写完整")
            return
        db.json_read('users.json')
        t = db.json_load
        d = {'username': self.username, 'password': self.password}

        if d in t:

            if d['username'] == 'ylz':
                tk.messagebox.showinfo("提示信息", "管理员登录成功")
                AdminPage(self.root)
                self.frame.pack_forget()
            else:
                tk.messagebox.showinfo("提示信息", "员工登录成功")
                StaffPage(self.root)
                self.frame.pack_forget()
        else:
            tk.messagebox.showinfo("提示信息", "登录失败,账号或密码错误")

